package enterprises

import grails.test.*

class EnterpriseTests extends GrailsUnitTestCase {
	Enterprise enterprise
	IndustrialSector industrialSector = new IndustrialSector()
	TypeOwnership typeOwnership = new TypeOwnership()

	protected void setUp() {
		super.setUp()
		enterprise = createEnterprise()
		mockForConstraintsTests(Enterprise, [enterprise]);
	}

	def createEnterprise() {
		new Enterprise(name:"asd", registrationNumber:1, industrialSector:industrialSector, typeOwnership:typeOwnership)
	}

	protected void tearDown() {
		super.tearDown()
	}

	void testEmptyName() {
		enterprise.name = ""
		assertFalse enterprise.validate()
		assertEquals "blank", enterprise.errors.name
	}

	void testSmallName() {
		enterprise.name = "as"
		assertFalse enterprise.validate()
		assertEquals "minSize", enterprise.errors.name;
	}

	void testNegativeCountWorkers() {
		enterprise.countWorkers = -1;
		assertFalse enterprise.validate()
		assertEquals "min", enterprise.errors.countWorkers
	}

	void testNegativeManCount() {
		enterprise.manCount = -1;
		assertFalse enterprise.validate()
		assertEquals "min", enterprise.errors.manCount
	}

	void testNegativeWomenCount() {
		enterprise.womenCount = -1;
		assertFalse enterprise.validate()
		assertEquals "min", enterprise.errors.womenCount
	}

	void testNegativeItrCount() {
		enterprise.itrCount = -1
		assertFalse enterprise.validate()
		assertEquals "min", enterprise.errors.itrCount
	}

	void testNegativeSummaryArea() {
		enterprise.summaryArea = -1
		assertFalse enterprise.validate()
		assertEquals "min", enterprise.errors.summaryArea
	}

	void testNegativeFreeArea() {
		enterprise.freeArea = -1
		assertFalse enterprise.validate()
		assertEquals "min", enterprise.errors.freeArea
	}

	void testNegativeBusyArea() {
		enterprise.busyArea = -1
		assertFalse enterprise.validate()
		assertEquals "min", enterprise.errors.busyArea
	}

	void testNegativePossibleBuildingArea() {
		enterprise.possibleBuildingArea = -1
		assertFalse enterprise.validate()
		assertEquals "min", enterprise.errors.possibleBuildingArea
	}

	void testUniqueName() {
		mockDomain(Enterprise, [createEnterprise()])
		assertFalse enterprise.validate()
		assertEquals "unique", enterprise.errors.name
	}

	void testUniqueRegistrationNumber() {		
		mockDomain(Enterprise, [createEnterprise()])		
		assertFalse enterprise.validate()
		assertEquals "unique", enterprise.errors.registrationNumber
	}
	
	void testNegativeRegistrationNumber() {
		enterprise.registrationNumber = 0
		assertFalse enterprise.validate()
		assertEquals "min", enterprise.errors.registrationNumber
	}
}
